import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zhrs/Utils/windowsSize.dart';
import 'package:zhrs/Model/medicaremessage.dart';
import 'package:zhrs/Model/message.dart';
import 'package:zhrs/mainpage/webviewpage.dart';
class  Medicallayout extends StatefulWidget{

  Function reset;
  Medicallayout({this.rowcount=3,this.total=8,this.medicalmessagelists,this.reset})
  {
    countcolum=(total/rowcount).toInt();
    if((total%rowcount)!=0)
      {
         countcolum=(total/rowcount).toInt()+1;
      }
    looptimes=new List<List<medicalmessage> >();

    for(int i=0;i<countcolum;i++)
      {
        List<medicalmessage> lists=new List<medicalmessage>();
        for(int j=i*rowcount;j<i*rowcount+rowcount;j++)
          {
            if(j>=medicalmessagelists.length)
              continue;
            lists.add(medicalmessagelists[j]);
          }
        looptimes.add(lists);
      }
  }
  int total;
  int rowcount;
  int countcolum;
  List<medicalmessage> medicalmessagelists;
  List<List<medicalmessage> > looptimes ;
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _Medicallayout();
  }
}

class _Medicallayout extends State<Medicallayout>
{
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      width: windowsSize.mapViewWidth  ,
      child: Column(

        children:
       widget. looptimes.map((medical)
       {
         return   Row(
           children: medical.map((mes)
           {
             return new GestureDetector(
                 onTap: ()
             {

                 if(mes.Url!=null)
                 {

                   widget.reset(url:mes.Url);
                   // Navigator.push(context, new MaterialPageRoute(
                   //  builder :(context)=>new Webviewpage(url:mes.Url ,),
                  // ));
                 }
                 else
                 {
                   showCupertinoDialogs(context, "建设中,敬请期待...");
                 }

             },
             child: Container(
               //color: Colors.red,
               height: windowsSize.mapViewWidth /widget.rowcount,
               width: windowsSize.mapViewWidth /widget.rowcount,
               decoration: new BoxDecoration(  border: new Border.all(color: Colors.black12, width: 0.5),),
               child:Center(
                 child: Container(
                   width:windowsSize.mapViewWidth /widget.rowcount ,
                   height:windowsSize.mapViewWidth /widget.rowcount ,
                   //color: Colors.red,
                   child:
                   Column(
                     mainAxisAlignment:MainAxisAlignment.center,
                     children: <Widget>[
                       ClipRRect(
                         borderRadius: const BorderRadius.all(const Radius.circular(360.0)),
                         child:Container(
                           color: mes.color,
                           height: windowsSize.mapViewWidth /widget.rowcount-70,
                           width:windowsSize.mapViewWidth /widget.rowcount-70,
                           child:  new Image.network(//加载网络图片
                             mes.imageUrl,

                             repeat: ImageRepeat.noRepeat,//图片重复方式
                           ),
                         ),
                       ),
                       Text(mes.title,style: TextStyle(fontSize:(1/widget.rowcount)*45.toDouble()),)
                     ],
                   ),
                 ),
               ),
             ),
             );

           }).toList()
         );
        }).toList()
       ),
     );
   }
 }